package day_1126;

import java.io.File;

/**
 * @author oldliu
 * @since 1.0
 */
public class FileSize {
    public static long getSize(File f) {
        if (!f.canRead())
            return 0;
        if (f.isFile()) {
            return f.length();
        }
        long sum = 0;
        sum += f.length();
        for (File f1 : f.listFiles()) {
            sum += getSize(f1);
        }
        return sum;
    }

    public static void main(String[] args) {
        long size = getSize(new File("H:\\mydocument\\桌面\\新建文件夹"));
        System.out.println(size);
    }

}
